package HomeWork;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    /**
     * 文件拷贝
     * @param source 原文件路径
     * @param dist 目标文件路径
     */
    public void copy(String source,String dist){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            String get = "";
            fis = new FileInputStream(source);
            fos = new FileOutputStream(dist);
            int n = 0;
            byte[] by = null;
            byte[] be = new byte[2048];
            while ((n = fis.read(be)) != -1){
               get =  new String(be,0,n);
            }
            by = get.getBytes();
            fos.write(by);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Test test = new Test();
        test.copy("src/HomeWork/小花.txt","src/HomeWork/Text/小花.txt");
    }
}
